package com.dt.jpa.service.impl;

import com.dt.jpa.bean.UserInfo;
import com.dt.jpa.dao.UserInfoDao;
import com.dt.jpa.redis.RedisUtils;
import com.dt.jpa.service.UserInfoService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoDao userInfoDao;

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public UserInfo getUserInfoById(String id){
        return userInfoDao.getAllByUserId(id);
    }

    @Override
    public void saveCache(String id){
        Gson gson = new Gson();
        UserInfo userInfo = userInfoDao.getAllByUserId("123123");
        System.out.println(userInfo.getUserId());
        redisUtils.set(id,gson.toJson(userInfo),200L);

    }
}
